<!-- 生产任务 -->
<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <!-- 搜索区域 -->
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item label="生产单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入生产单号查询" v-model="queryParam.productionNum"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入产品名称查询" v-model="queryParam.productName"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入客户名称查询" v-model="queryParam.customerName"></a-input>
                </a-form-item>
              </a-col>
              <!--   <a-col :md="6" :sm="24">
                <a-form-item label="所属行业" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-select
                    v-model="queryParam.industry"
                    allowClear
                    placeholder="请选择"
                    showSearch
                    optionFilterProp="children"
                  >
                    <a-select-option v-for="(item, index) in industry" :key="index" :value="item.codeKey">
                      {{ item.codeValue }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col> -->
              <!-- <a-col :md="6" :sm="24">
                <a-form-item label="基材分类" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-select
                    v-model="queryParam.baseMaterial"
                    allowClear
                    placeholder="请选择"
                    showSearch
                    optionFilterProp="children"
                  >
                    <a-select-option v-for="(item, index) in baseMaterial" :key="index" :value="item.codeKey">
                      {{ item.codeValue }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col> -->
              <!-- <a-col :md="6" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="下发时间">
                  <a-date-picker
                    style="width: 100%"
                    v-model="queryParam.issueDate"
                    format="YYYY-MM-DD"
                    placeholder="请选择下发时间"
                  />
                </a-form-item>
              </a-col> -->
              <!-- <a-col :md="6" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="发货日期">
                  <a-date-picker
                    style="width: 100%"
                    v-model="queryParam.deliverDate"
                    format="YYYY-MM-DD"
                    placeholder="请选择发货日期"
                  />
                </a-form-item>
              </a-col> -->
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-col :md="6" :sm="24">
                  <a-button type="primary" @click="searchQuery">查询</a-button>
                  <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
                </a-col>
              </span>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator" style="margin-top: 5px">
          <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
        </div>
        <!-- table区域-begin -->
        <div class="tableDiv">
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            @change="handleTableChange"
          >
            <span slot="action" slot-scope="text, record">
              <a @click="handleSee(record)">详情</a>
              <a-divider type="vertical" />
              <a @click="handleEdit(record)">编辑</a>
              <a-divider type="vertical" />
              <a-popconfirm title="确定删除吗?" @confirm="() => myhandleDelete(record.id)">
                <a>删除</a>
              </a-popconfirm>
            </span>
            <span slot="Gy" slot-scope="text, record">
              <a-tag color="blue" @click="handleAlert(record)" type="primary" icon="plus"><a>查看钢印</a></a-tag>
            </span>
            <span slot="industry" slot-scope="text, record">
              <div v-for="(item, index) in industry">{{ item.codeKey == record.industry ? item.codeValue : '' }}</div>
            </span>
            <span slot="baseMaterial" slot-scope="text, record">
              <div v-for="(item, index) in baseMaterial">
                {{ item.codeKey == record.baseMaterial ? item.codeValue : '' }}
              </div>
            </span>
            <!-- 状态渲染模板 -->
            <template slot="customRenderFlag" slot-scope="enabled">
              <a-tag v-if="enabled" color="green">启用</a-tag>
              <a-tag v-if="!enabled" color="orange">禁用</a-tag>
            </template>
          </a-table>
        </div>
        <!-- table区域-end -->
        <!-- 表单区域 -->
        <ProductionTaskModel ref="modalForm" @ok="modalFormOk"></ProductionTaskModel>
        <StampModel ref="StampModalForm" @ok="modalFormOk"></StampModel>
      </a-card>
    </a-col>
  </a-row>
</template>
<script>
import ProductionTaskModel from './modules/ProductionTaskModel'
import StampModel from './modules/StampModel'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction, deleteAction } from '@/api/manage'
import { openDownloadDialog, sheet2blob } from '@/utils/util'
import JDate from '@/components/jeecg/JDate'
export default {
  name: 'ProductionTask',
  mixins: [JeecgListMixin],
  components: {
    ProductionTaskModel,
    StampModel,
    JDate
  },
  data() {
    return {
      labelCol: {
        span: 5
      },
      wrapperCol: {
        span: 18,
        offset: 1
      },
      industry: null,
      baseMaterial: null,
      // 查询条件
      queryParam: {
        supplier: '',
        type: '客户',
        telephone: '',
        phonenum: ''
      },
      ipagination: {
        pageSizeOptions: ['10', '20', '30', '100', '200']
      },
      // 表头
      columns: [
        // {
        //   title: '#',
        //   dataIndex: '',
        //   key:'rowIndex',
        //   width:60,
        //   align:"center",
        //   customRender:function (t,r,index) {
        //     return parseInt(index)+1;
        //   },
        //   fixed: 'left'
        // },
        { title: '生产单号', dataIndex: 'productionNum', key: '1', width: 70, align: 'center' },
        // { title: '内部编码', dataIndex: 'contractCode', key: '3', width: 150, align: 'center' },
        // {
        //   title: '所属行业',
        //   dataIndex: 'industry',
        //   key: '11',
        //   width: 150,
        //   align: 'center',
        //   scopedSlots: { customRender: 'industry' }
        // },
        { title: '产品名称', dataIndex: 'productName', key: '3', width: 70, align: 'center' },
        { title: '客户名称', dataIndex: 'customerName', key: '4', width: 70, align: 'center' },
        {
          title: '基材分类',
          dataIndex: 'baseMaterial',
          key: '5',
          width: 70,
          align: 'center',
          scopedSlots: { customRender: 'baseMaterial' }
        },
        { title: '下发日期', dataIndex: 'issueDate', key: '6', width: 70, align: 'center' },
        { title: '发货日期', dataIndex: 'deliverDate', key: '7', width: 70, align: 'center' },
        { title: '单双面', dataIndex: 'layer', width: 70, key: '9', align: 'center' },
        { title: '规格型号', dataIndex: 'spec', key: '8', width: 70, align: 'center' },
        { title: '生产数量', dataIndex: 'amount', key: '8', width: 70, align: 'center' },
        // { title: '', dataIndex: 'model', key: '10', width: 100, align: 'center' },
        { title: '钢印号', dataIndex: '', key: '13', width: 70, align: 'center', scopedSlots: { customRender: 'Gy' } },
        {
          title: '操作',
          dataIndex: 'action',
          key: '25',
          width: 120,
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '	/productionPlan/getPage',
        delete: '/productionPlan/remove'
      }
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}${this.url.importExcelUrl}`
    }
  },
  mounted() {
    this.getIndustry()
    this.getDictionary()
    console.log('236', document.getElementsByClassName('tableDiv')[0].width)
  },
  methods: {
    getIndustry() {
      const params = {
        codeType: 'industry'
      }
      getAction('/generalDict/getList', params).then(res => {
        if (res.code === 200 || res.code === 10000) {
          this.industry = res.data.records
        }
      })
    },
    getDictionary() {
      const params = {
        codeType: 'baseMaterial'
      }
      getAction('/generalDict/getList', params).then(res => {
        if (res.code === 200 || res.code === 10000) {
          this.baseMaterial = res.data.records
        }
      })
    },
    handleAlert(productionNum) {
      this.$refs.StampModalForm.edit(productionNum)
      this.$refs.StampModalForm.title = '新增'
      this.$refs.StampModalForm.disableSubmit = false
    },
    searchReset() {
      this.queryParam = {
        type: '客户'
      }
      this.loadData(1)
    },
    myhandleDelete: function(id) {
      if (!this.url.delete) {
        this.$message.error('请设置url.delete属性!')
        return
      }
      var that = this
      let params = {
        id: id
      }
      deleteAction(that.url.delete, params).then(res => {
        if (res.code === 200 || res.code === 10000) {
          that.$message.success(res.data.message || '删除成功')
          that.loadData()
        } else {
          that.$message.warning(res.data.message)
        }
      })
    },
    handleEdit: function(record) {
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '编辑'
      this.$refs.modalForm.disableSubmit = false
      if (this.btnEnableList.indexOf(1) === -1) {
        this.$refs.modalForm.isReadOnly = false
      }
    },
    //查看详情
    handleSee: function(record) {
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '详情'
      this.$refs.modalForm.disableSubmit = true
      if (this.btnEnableList.indexOf(1) === -1) {
        this.$refs.modalForm.isReadOnly = true
      }
    }
  }
}
</script>
<style scoped>
/** Button按钮间距 */
.table-operator .ant-btn {
  margin: 0 8px 8px 0;
}
@import '~@assets/less/common.less';
</style>
